﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

namespace Directory.Web
{
	public partial class AjaxResponse : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			Response.Clear();
			string action = null;
			try
			{
				action = Request.QueryString["action"].Trim();
			}
			catch
			{
			}
			if (!string.IsNullOrEmpty(action))
			{
				switch (action.ToLower())
				{
					case "getcateogrychilds":
						GetCateoryChilds();
						break;
					default :
						break;
				}
			}
			Response.End();
		}

		private void GetCateoryChilds()
		{
			int cateogryId;
			if (!int.TryParse(Request.QueryString["categoryId"], out cateogryId))
			{
				return;
			}
			IList<Directory.Model.CategoryInfo> childList = CategoryDataProxy.GetChildsOfCategory(cateogryId);
			StringBuilder sb = new StringBuilder();
			if (childList.Count > 0)
			{
				sb.Append("<select>");
				sb.Append("<option CategoryId=\"-999\" CategoryName=\"选择\" IsSelected=\"1\" />");
				foreach (Directory.Model.CategoryInfo cat in childList)
				{
					sb.Append("<option CategoryId=\""+cat.CategoryId.ToString()+"\" CategoryName=\""+cat.CategoryName+"\" IsSelected=\"0\" />");
				}
				sb.Append("</select>");
			}
			Response.ContentType = "text/xml";
			Response.Write(sb.Replace("\\n", "").ToString());
		}
	}
}